package com.asj.websocket;

import com.asj.MainActivity;
//import com.oplus.enterprise.mdmcoreservice.manager.DeviceSecurityManager;
import com.asj.service.oppoSdk.OPPOSDKService;
import com.asj.utils.CommonsUtils;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.WebSocket;

public class WebSocketClient {
    //设备客户端管理
    private static WebSocketClient instance;
    private final MainActivity mainActivity; // 用于持有 MainActivity 的引用


    // 私有构造函数
    private WebSocketClient(MainActivity mainActivity) {
        this.mainActivity = mainActivity;
    }

    // 获取单例的方法
    public static synchronized WebSocketClient getInstance(MainActivity mainActivity) {
        if (instance == null) {
            instance = new WebSocketClient(mainActivity);
        }
        return instance;
    }

    //初始化webSocket
    public WebSocket initWebSocket(){
        // 创建WebSocket客户端
        Request request = new Request.Builder()
//                .url("ws://8.138.42.163:8090/luxuryMachine/middleGroundWebsocket") // 设置中台WebSocket服务器的URL
//                .url("ws://www.aisheji.team:8090/luxuryMachine/middleGroundWebsocket") // 设置中台WebSocket服务器的URL
                .url("ws://192.168.1.193:8090/luxuryMachine/middleGroundWebsocket") // 设置中台WebSocket服务器的URL
                .build();
        // 使用 mainActivity 的引用来初始化 WebSocketListener
        return new OkHttpClient().newWebSocket(
                request,
                new LuxuryMachineWebSocketListener(mainActivity,
                        this,
                        CommonsUtils.getDeviceCode(new OPPOSDKService(mainActivity).getIMEI()),
                        120,
                        3)
        );
    }


}
